FlowType
PackageAxial
Represents a cold workflow that reads an environment, returns a typed result, and is executed
explicitly through one of its execution members such as
ToTask, ToAsync, or RunSynchronously.
Specification
Kind
Type
Members
109
Examples
0
scopeAsyncFinalizerSignature
scopeAsyncFinalizer finalizer
ofExitSignature
ofExit exit
scopeFinalizerSignature
scopeFinalizer finalizer
scopeDisposableSignature
scopeDisposable resource
scopeAsyncDisposableSignature
scopeAsyncDisposable resource
Summary
| Name | Signature | Synopsis |
|---|---|---|
| Union cases | ||
| RunSynchronously | this.RunSynchronously | Starts the workflow and blocks until the final exit is available. |
| StartAsTask | this.StartAsTask | Starts the workflow immediately and returns a task handle for its final exit. |
| StartAsValueTask | this.StartAsValueTask | Starts the workflow immediately and returns a value-task handle for its final exit. |
| ToAsync | this.ToAsync | Builds a cold async that runs the workflow when it is started. |
| Operations | ||
| scopeAsyncFinalizer | scopeAsyncFinalizer finalizer | Registers a F# async finalizer with the current runtime scope on .NET or Fable. |
| ofExit | ofExit exit | Creates a flow from an execution outcome. |
| scopeFinalizer | scopeFinalizer finalizer | Registers an asynchronous finalizer with the current runtime scope. |
| scopeDisposable | scopeDisposable resource | Registers a disposable resource with the current runtime scope. |
| scopeAsyncDisposable | scopeAsyncDisposable resource | Registers an asynchronously disposable resource with the current runtime scope. |
| scopeResource | scopeResource (Resource(acquire, register) | Acquires a described resource and registers its release with the current runtime scope. |
| scopeAcquireRelease | scopeAcquireRelease acquire release | Acquires a value and registers its release with the current runtime scope. |
| scoped | scoped flow | Runs a flow in a child scope and closes that scope before returning. |
| fromAsync | fromAsync operation | Creates a flow from a raw async operation. |
| fromAsyncResult | fromAsyncResult operation | Creates a flow from an async operation whose Error enters the typed error channel. |
| attemptAsync | attemptAsync operation | Creates a flow from an async operation and treats thrown exceptions as recoverable typed errors. |
| fromBlocking | fromBlocking operation | Creates a flow from synchronous, blocking work, such as a database driver or native library call. |
| fromBlockingResult | fromBlockingResult operation | Creates a flow from blocking work whose Error enters the typed error channel. |
| attemptBlocking | attemptBlocking operation | Creates a flow from blocking work and treats thrown exceptions as recoverable typed errors. |
| fromTask | fromTask factory | Creates a flow from a cancellable task factory. |
| fromTaskResult | fromTaskResult factory | Creates a flow from a cold task factory whose Error enters the typed error channel. |
| attemptTask | attemptTask factory | Creates a flow from a cancellable task factory and treats thrown exceptions as recoverable typed errors. |
| fromValueTask | fromValueTask factory | Creates a flow from a cancellable value-task factory. |
| fromValueTaskResult | fromValueTaskResult factory | Creates a flow from a cold value-task factory whose Error enters the typed error channel. |
| attemptValueTask | attemptValueTask factory | Creates a flow from a cancellable value-task factory and treats thrown exceptions as recoverable typed errors. |
| awaitStartedTask | awaitStartedTask startedTask | Observes a task that has already been started. |
| awaitStartedTaskResult | awaitStartedTaskResult startedTask | Observes an already-started task whose Error enters the typed error channel. |
| attemptStartedTask | attemptStartedTask startedTask | Observes a task that has already been started and treats thrown exceptions as recoverable typed errors. |
| awaitStartedValueTask | awaitStartedValueTask startedValueTask | Observes a value task that has already been started. |
| awaitStartedValueTaskResult | awaitStartedValueTaskResult startedValueTask | Observes an already-started value task whose Error enters the typed error channel. |
| attemptStartedValueTask | attemptStartedValueTask startedValueTask | Observes a value task that has already been started and treats thrown exceptions as recoverable typed errors. |
| ok | ok value | Creates a successful synchronous flow. |
| succeed | succeed value | Same as ok. |
| error | error failure | Creates a failing synchronous flow. |
| fail | fail failure | Same as error. |
| die | die exn | Creates a defective flow that fails with an exception. |
| fromResult | fromResult result | Lifts a into a synchronous flow. |
| verify | verify policy input | Creates a flow that verifies an input with an environment-aware policy. |
| withFiberObserver | withFiberObserver observer flow | Installs runtime fiber-lifecycle hooks for diagnostics and telemetry. |
| addFiberObserver | addFiberObserver observer flow | Adds runtime fiber-lifecycle hooks, composing with any observer already installed. |
| withFiberRegistry | withFiberRegistry registry flow | Tracks every fiber forked inside the flow in registry. |
| withAnnotationSink | withAnnotationSink sink flow | Installs a runtime annotation sink for integration packages. |
| addAnnotationSink | addAnnotationSink sink flow | Adds a runtime annotation sink, composing with any sink already installed. |
| annotate | annotate name value flow | Adds a runtime annotation for the duration of the supplied flow. |
| withTraceId | withTraceId traceId flow | Adds the standard trace_id runtime annotation for the duration of the supplied flow. |
| cancellationToken | cancellationToken | Reads the current runtime cancellation token. |
| ensureNotCanceled | ensureNotCanceled | Stops with Cause.Interrupt if the runtime's cancellation token has been cancelled. |
| catchCancellation | catchCancellation handler flow | Turns cancellation that a flow raised for its own reasons into a typed error. |
| sleep | sleep delay | Suspends the flow for the specified duration, observing cancellation. |
| scope | scope | Reads the current runtime scope. |
| annotations | annotations | Reads the current runtime annotations. |
| traceId | traceId | Reads the current trace id annotation, if one is present. |
| fiberId | fiberId | Reads the current fiber id from the ambient runtime context. |
| timeout | timeout after timeoutError flow | Fails with the supplied typed error when the flow does not complete before the timeout. |
| timeoutToOk | timeoutToOk after value flow | Returns the supplied success value when the flow does not complete before the timeout. |
| timeoutToError | timeoutToError after error flow | Same as timeout; named to pair with timeoutToOk. |
| timeoutWith | timeoutWith after fallback flow | Runs a fallback flow when the source flow does not complete before the timeout. |
| retry | retry schedule flow | Retries a flow's typed failures according to a schedule. |
| repeat | repeat schedule flow | Repeats a successful flow according to a schedule. |
| supervise | supervise schedule flow | Restarts a flow that terminates with an unexpected defect, according to a schedule. |
| fork | fork flow | Starts a flow in a new fiber without waiting for it to complete. |
| forkNamed | forkNamed name flow | Starts a flow in a new fiber carrying a diagnostic name. |
| forkGraceful | forkGraceful stop grace flow | Starts a flow in a new fiber that, when its forking scope closes, is asked to stop and given time to finish before it is interrupted. |
| forkDetached | forkDetached flow | Starts a flow in a new fiber that is deliberately never awaited. |
| memoize | memoize flow | Returns a flow that runs flow at most once at a time and remembers its value. |
| forkReplacing | forkReplacing slot flow | Starts a flow in a new fiber held by slot, interrupting the fiber it replaces. |
| forkReplacingKey | forkReplacingKey key slots flow | Starts a flow in a new fiber held under key, interrupting that key's previous fiber. |
| zipPar | zipPar left right | Combines two flows into a tuple of their values, running them concurrently. |
| sequencePar | sequencePar flows | Runs all flows concurrently and returns their values in input order. |
| race | race left right | Runs two flows concurrently and returns the result of the first one to complete. |
| fromOption | fromOption error value | Lifts an option into a synchronous flow with the supplied error. |
| fromValueOption | fromValueOption error value | Lifts a value option into a synchronous flow with the supplied error. |
| orElseFlow | orElseFlow errorFlow result | Attaches an environment-derived error to a result that failed without one; the error flow runs only on failure. |
| env | env | Reads the current environment as the successful flow value. |
| envWith | envWith projection | Projects one value from the current environment. |
| map | map mapper flow | Transforms the successful value of a flow. |
| ignore | ignore flow | Maps the successful value of a synchronous flow to unit. |
| bind | bind binder flow | Sequences a dependent flow after a successful value. |
| (>>=) | flow >>= binder | Sequences a synchronous continuation after a successful value. |
| tap | tap binder flow | Runs an effect on success and preserves the original value. |
| tapError | tapError binder flow | Runs a synchronous side effect on failure and preserves the original error. |
| mapError | mapError mapper flow | Maps the error value of a synchronous flow. |
| widenError | widenError flow | Gives a flow that cannot fail with a typed error any error type. |
| tracedError | tracedError trace flow | Attaches diagnostic trace text to any failure cause of the flow. |
| mapBoth | mapBoth onSuccess onFailure flow | Maps both the successful value and the failure cause of a synchronous flow. |
| fold | fold onSuccess onFailure flow | Folds both the successful value and the failure cause into a new flow. |
| onExit | onExit handler flow | Runs a handler with the flow's final outcome, whether it succeeded, failed, or was interrupted. |
| ensuring | ensuring finalizer flow | Runs a finalizer after the flow, however it ends. |
| onInterrupt | onInterrupt handler flow | Runs a handler only if the flow is interrupted. |
| never | never | A flow that never completes on its own; it ends only when it is interrupted. |
| catch | catch handler flow | Catches exceptions raised during execution and simple defect outcomes, then maps them to a typed error. |
| orElseWith | orElseWith fallback flow | Computes a fallback flow from the typed error when the source flow fails. |
| orElse | orElse fallback flow | Falls back to another flow when the source flow fails. |
| zip | zip left right | Runs two flows sequentially and combines their successful values into a tuple. |
| map2 | map2 mapper left right | Combines two flows with a mapping function. |
| apply | apply flow value | Applies a flow-wrapped function to a flow-wrapped value. |
| map3 | map3 mapper left middle right | Combines three flows with a mapping function. |
| (<!>) | mapper flow | Maps the successful value of a synchronous flow. |
| (<*>) | flow <*> value | Applies a flow-wrapped function to a flow-wrapped value. |
| localEnv | localEnv mapping flow | Runs a flow against an environment derived from the outer environment. |
| delay | delay factory | Defers flow construction until execution time. |
| traverse | traverse mapping values | Transforms a sequence of values into a flow and stops at the first failure. |
| traversePar | traversePar parallelism mapping values | Maps values to flows and runs them with bounded concurrency, returning results in input order. |
| traverseParUsing | traverseParUsing parallelism resource mapping values | Like traversePar, giving each worker its own resource, acquired once and reused for every value it maps. |
| forEachPar | forEachPar parallelism action values | Runs a flow for each value with bounded concurrency, discarding the results. |
| forEachParUsing | forEachParUsing parallelism resource action values | Like forEachPar, giving each worker its own resource, acquired once and reused for every value it processes. |
| sequence | sequence flows | Transforms a sequence of flows into a flow of a sequence and stops at the first failure. |
| toAsync | toAsync environment flow | Builds a cold async that runs the workflow when it is started. |
| startTask | startTask environment flow | Starts the workflow immediately and returns a task handle for its final exit. |
| run | run environment flow | Runs the workflow and blocks until the final exit is available. |
Union cases
kind:member
kind:member
kind:member
Operations
kind:member
Registers a F# async finalizer with the current runtime scope on .NET or Fable.
Parameters
| Name | Type | Description |
|---|---|---|
| finalizer | CancellationToken -> Async<unit> |
Returns
Flow<'env, 'error, unit>
Verification Examples
Flow.scopeAsyncFinalizer (fun _ -> async { resource.Close() })kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
Acquires a value and registers its release with the current runtime scope.
Parameters
| Name | Type | Description |
|---|---|---|
| acquire | Flow<'env, 'error, 'resource> | The flow that acquires the value. |
| release | 'resource -> CancellationToken -> Task | The release action run when the current scope closes. |
Returns
Flow<'env, 'error, 'resource>
kind:member
kind:member
kind:member
kind:member
kind:member
Creates a flow from synchronous, blocking work, such as a database driver or native library call.
Parameters
| Name | Type | Description |
|---|---|---|
| operation | CancellationToken -> 'value | The blocking operation, observing the supplied cancellation token where it can. |
Returns
Flow<'env, 'error, 'value>
Verification Examples
let commits = Flow.fromBlocking (fun _ -> repository.Commits |> Seq.truncate 50 |> List.ofSeq)kind:member
Creates a flow from blocking work whose
Error enters the typed error channel.Parameters
| Name | Type | Description |
|---|---|---|
| operation | CancellationToken -> Result<'value, 'error> | The blocking operation, observing the supplied cancellation token where it can. |
Returns
Flow<'env, 'error, 'value>
kind:member
Creates a flow from blocking work and treats thrown exceptions as recoverable typed errors.
Parameters
| Name | Type | Description |
|---|---|---|
| operation | CancellationToken -> 'value | The blocking operation, observing the supplied cancellation token where it can. |
Returns
Flow<'env, exn, 'value>
kind:member
Creates a flow from a cancellable task factory.
Parameters
| Name | Type | Description |
|---|---|---|
| factory | CancellationToken -> Task<'value> | Starts the operation, observing the supplied cancellation token. |
Returns
Flow<'env, 'error, 'value>
Verification Examples
let flow = Flow.fromTask (fun token -> client.GetStringAsync(url, token))kind:member
kind:member
Creates a flow from a cancellable task factory and treats thrown exceptions as recoverable typed errors.
Parameters
| Name | Type | Description |
|---|---|---|
| factory | CancellationToken -> Task<'value> | Starts the operation, observing the supplied cancellation token. |
Returns
Flow<'env, exn, 'value>
kind:member
kind:member
kind:member
Creates a flow from a cancellable value-task factory and treats thrown exceptions as recoverable typed errors.
Parameters
| Name | Type | Description |
|---|---|---|
| factory | CancellationToken -> ValueTask<'value> | Starts the operation, observing the supplied cancellation token. |
Returns
Flow<'env, exn, 'value>
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
Observes a value task that has already been started and treats thrown exceptions as recoverable typed errors.
Parameters
| Name | Type | Description |
|---|---|---|
| startedValueTask | ValueTask<'value> | A value task that is already running. |
Returns
Flow<'env, exn, 'value>
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
Installs runtime fiber-lifecycle hooks for diagnostics and telemetry.
Parameters
| Name | Type | Description |
|---|---|---|
| observer | FiberObserver | The lifecycle hooks. Start from FiberObserver.none and override what you need. |
| flow | Flow<'env, 'error, 'value> | The source flow. |
Returns
Flow<'env, 'error, 'value>
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
Stops with
Cause.Interrupt if the runtime's cancellation token has been cancelled.Returns
Flow<'env, 'error, unit>
Verification Examples
let sumSquares (values: int list) : Flow<unit, string, int> =
flow {
let mutable total = 0
for value in values do
do! Flow.ensureNotCanceled
total <- total + value * value
return total
}kind:member
Turns cancellation that a flow raised for its own reasons into a typed error.
Parameters
| Name | Type | Description |
|---|---|---|
| handler | OperationCanceledException -> 'error | Maps the cancellation exception into the workflow error type. |
| flow | Flow<'env, 'error, 'value> | The source flow. |
Returns
Flow<'env, 'error, 'value>
kind:member
kind:member
kind:member
kind:member
kind:member
Fails with the supplied typed error when the flow does not complete before the timeout.
Parameters
| Name | Type | Description |
|---|---|---|
| after | TimeSpan | The timeout duration. |
| timeoutError | 'error | The typed error returned when the timeout wins. |
| flow | Flow<'env, 'error, 'value> | The source flow. |
Returns
Flow<'env, 'error, 'value>
kind:member
Returns the supplied success value when the flow does not complete before the timeout.
Parameters
| Name | Type | Description |
|---|---|---|
| after | TimeSpan | The timeout duration. |
| value | 'value | The success value returned when the timeout wins. |
| flow | Flow<'env, 'error, 'value> | The source flow. |
Returns
Flow<'env, 'error, 'value>
kind:member
kind:member
Runs a fallback flow when the source flow does not complete before the timeout.
Parameters
| Name | Type | Description |
|---|---|---|
| after | TimeSpan | The timeout duration. |
| fallback | unit -> Flow<'env, 'error, 'value> | Creates the fallback flow when the timeout wins. |
| flow | Flow<'env, 'error, 'value> | The source flow. |
Returns
Flow<'env, 'error, 'value>
kind:member
Retries a flow's typed failures according to a schedule.
Parameters
| Name | Type | Description |
|---|---|---|
| schedule | Schedule<'env, 'error, 'output> | Decides, from each typed error, whether to retry and after what delay. |
| flow | Flow<'env, 'error, 'value> | The flow to retry. |
Returns
Flow<'env, 'error, 'value>
Verification Examples
fetch |> Flow.retry (Schedule.recurs 3)
fetch |> Flow.retry (Retry.schedule { Retry.defaults with When = HttpError.isTransient })kind:member
Repeats a successful flow according to a schedule.
Parameters
| Name | Type | Description |
|---|---|---|
| schedule | Schedule<'env, 'value, 'output> | Decides, from each value, whether to repeat and after what delay. |
| flow | Flow<'env, 'error, 'value> | The flow to repeat. |
Returns
Flow<'env, 'error, 'value>
Verification Examples
heartbeat |> Flow.repeat (Schedule.spaced (TimeSpan.FromSeconds 5.0))kind:member
Restarts a flow that terminates with an unexpected defect, according to a schedule.
Parameters
| Name | Type | Description |
|---|---|---|
| schedule | Schedule<'env, exn, 'output> | Decides, from each defect, whether to restart and after what delay. |
| flow | Flow<'env, 'error, 'value> | The flow to supervise. |
Returns
Flow<'env, 'error, 'value>
Verification Examples
worker |> Flow.supervise (Retry.schedule { Retry.defaults with Retries = 5 })kind:member
kind:member
kind:member
Starts a flow in a new fiber that, when its forking scope closes, is asked to stop and given time to finish
before it is interrupted.
Parameters
| Name | Type | Description |
|---|---|---|
| stop | Flow<'env, Never, unit> | Asks the fiber to finish, for example by shutting down the queue it consumes. |
| grace | TimeSpan | How long to wait after stop before interrupting the fiber. |
| flow | Flow<'env, 'error, 'value> | The flow to fork. |
Returns
Flow<'env, 'none, Fiber<'error, 'value>>
Verification Examples
flow {
let! (samples: Queue<float>) = Queue.bounded 1000
let! _ =
samples
|> FlowStream.fromDequeue
|> FlowStream.runForEachFlow writeSample
|> Flow.forkGraceful (Dequeue.shutdown samples) (TimeSpan.FromSeconds 5.0)
do! samples |> Queue.offer 21.5 |> Flow.ignore
}
|> Flow.scoped // closing the scope flushes every offered sample before returningkind:member
kind:member
Returns a flow that runs
flow at most once at a time and remembers its value.Parameters
| Name | Type | Description |
|---|---|---|
| flow | Flow<'env, 'error, 'value> | The computation to share. |
Returns
Flow<'env, 'none, Flow<'caller, 'error, 'value>>
Verification Examples
let readConfig : Flow<unit, string, string> = Flow.delay (fun () -> Flow.ok "config")
let sameConfig : Flow<unit, string, bool> =
flow {
let! loadConfig = Flow.memoize readConfig
let! a = loadConfig
let! b = loadConfig // readConfig ran once
return a = b
}kind:member
Starts a flow in a new fiber held by
slot, interrupting the fiber it replaces.Parameters
| Name | Type | Description |
|---|---|---|
| slot | FiberSlot<'error, 'value> | The slot that holds the current fiber. |
| flow | Flow<'env, 'error, 'value> | The flow to run. |
Returns
Flow<'env, 'none, Fiber<'error, 'value>>
Verification Examples
let onQueryChanged slot query =
search query |> Flow.forkReplacing slot |> Flow.ignorekind:member
Starts a flow in a new fiber held under
key, interrupting that key's previous fiber.Parameters
| Name | Type | Description |
|---|---|---|
| key | 'key | The key whose previous fiber is replaced. |
| slots | KeyedFiberSlot<'key, 'error, 'value> | The keyed slot that holds the current fibers. |
| flow | Flow<'env, 'error, 'value> | The flow to run. |
Returns
Flow<'env, 'none, Fiber<'error, 'value>>
Verification Examples
loadPreview document |> Flow.forkReplacingKey document.Id previewskind:member
Combines two flows into a tuple of their values, running them concurrently.
Parameters
| Name | Type | Description |
|---|---|---|
| left | Flow<'env, 'error, 'left> | The first flow to combine. |
| right | Flow<'env, 'error, 'right> | The second flow to combine. |
Returns
Flow<'env, 'error, ('left * 'right)>
Verification Examples
let combined = Flow.zipPar (Flow.succeed 1) (Flow.succeed 2)
combined |> Flow.run ()kind:member
kind:member
Runs two flows concurrently and returns the result of the first one to complete.
Parameters
| Name | Type | Description |
|---|---|---|
| left | Flow<'env, 'error, 'value> | The first flow to run. |
| right | Flow<'env, 'error, 'value> | The second flow to run. |
Returns
Flow<'env, 'error, 'value>
Verification Examples
let fastOrSlow = Flow.race (Flow.succeed "cached") (Flow.succeed "loaded")
fastOrSlow |> Flow.run ()kind:member
Lifts an option into a synchronous flow with the supplied error.
Parameters
| Name | Type | Description |
|---|---|---|
| error | 'error | The error to return if the option is None. |
| value | 'value option | The option to lift. |
Returns
Flow<'env, 'error, 'value>
Verification Examples
let opt = Some "value"
Flow.fromOption "missing" opt |> Flow.run ()kind:member
kind:member
Attaches an environment-derived error to a result that failed without one; the error flow runs only on failure.
Parameters
| Name | Type | Description |
|---|---|---|
| errorFlow | Flow<'env, 'error, 'error> | A flow that reads the environment to produce an error value. |
| result | Result<'value, unit> | The pure result to bridge. |
Returns
Flow<'env, 'error, 'value>
Verification Examples
let result = Result.Error ()
let flow = Flow.orElseFlow (Flow.envWith (fun env -> "error")) resultkind:member
kind:member
Projects one value from the current environment.
Parameters
| Name | Type | Description |
|---|---|---|
| projection | 'env -> 'value | A function that extracts a value from the environment. |
Returns
Flow<'env, 'error, 'value>
Verification Examples
let currentTime () =
Flow.envWith (fun (environment: BaseRuntime) -> environment.Clock.UtcNow())kind:member
Transforms the successful value of a flow.
Parameters
| Name | Type | Description |
|---|---|---|
| mapper | 'value -> 'next | A function of type 'value -> 'next to transform the successful value. |
| flow | Flow<'env, 'error, 'value> | The source flow of type Axial`3 to transform. |
Returns
Flow<'env, 'error, 'next>
Verification Examples
let flow = Flow.succeed 1 |> Flow.map (fun x -> x + 1)kind:member
kind:member
Sequences a dependent flow after a successful value.
Parameters
| Name | Type | Description |
|---|---|---|
| binder | 'value -> Flow<'env, 'error, 'next> | A function that takes the successful value and returns a new flow. |
| flow | Flow<'env, 'error, 'value> | The source flow to sequence. |
Returns
Flow<'env, 'error, 'next>
Verification Examples
let flow = Flow.succeed 1 |> Flow.bind (fun x -> Flow.succeed (x + 1))kind:member
kind:member
Runs an effect on success and preserves the original value.
Parameters
| Name | Type | Description |
|---|---|---|
| binder | 'value -> Flow<'env, 'error, unit> | A function that produces a side-effect flow from the successful value. |
| flow | Flow<'env, 'error, 'value> | The source flow. |
Returns
Flow<'env, 'error, 'value>
Verification Examples
let flow = Flow.succeed 42 |> Flow.tap (fun x -> Flow.succeed ())kind:member
Runs a synchronous side effect on failure and preserves the original error.
Parameters
| Name | Type | Description |
|---|---|---|
| binder | 'error -> Flow<'env, 'error, unit> | A function that produces a side-effect flow from the error value. |
| flow | Flow<'env, 'error, 'value> | The source flow. |
Returns
Flow<'env, 'error, 'value>
Verification Examples
let flow = Flow.fail "error" |> Flow.tapError (fun err -> Flow.succeed ())kind:member
Maps the error value of a synchronous flow.
Parameters
| Name | Type | Description |
|---|---|---|
| mapper | 'error -> 'nextError | The function to transform the error value. |
| flow | Flow<'env, 'error, 'value> | The source flow. |
Returns
Flow<'env, 'nextError, 'value>
Verification Examples
let flow = Flow.fail "error" |> Flow.mapError (fun err -> err + "!")kind:member
kind:member
Attaches diagnostic trace text to any failure cause of the flow.
Parameters
| Name | Type | Description |
|---|---|---|
| trace | string | The diagnostic trace text, typically an operation or boundary name. |
| flow | Flow<'env, 'error, 'value> | The source flow. |
Returns
Flow<'env, 'error, 'value>
Verification Examples
let flow = loadUser |> Flow.tracedError "billing.load-user"kind:member
Maps both the successful value and the failure cause of a synchronous flow.
Parameters
| Name | Type | Description |
|---|---|---|
| onSuccess | 'value -> 'next | The function to transform the success value. |
| onFailure | Cause<'error> -> Cause<'nextError> | The function to transform the failure cause. |
| flow | Flow<'env, 'error, 'value> | The source flow. |
Returns
Flow<'env, 'nextError, 'next>
kind:member
Folds both the successful value and the failure cause into a new flow.
Parameters
| Name | Type | Description |
|---|---|---|
| onSuccess | 'value -> Flow<'env, 'nextError, 'next> | A function that returns a new flow from the success value. |
| onFailure | Cause<'error> -> Flow<'env, 'nextError, 'next> | A function that returns a new flow from the failure cause. |
| flow | Flow<'env, 'error, 'value> | The source flow. |
Returns
Flow<'env, 'nextError, 'next>
kind:member
Runs a handler with the flow's final outcome, whether it succeeded, failed, or was interrupted.
Parameters
| Name | Type | Description |
|---|---|---|
| handler | Exit<'value, 'error> -> Flow<'env, Never, unit> | Receives the flow's Exit; it cannot fail with a typed error. |
| flow | Flow<'env, 'error, 'value> | The source flow. |
Returns
Flow<'env, 'error, 'value>
Verification Examples
transfer
|> Flow.onExit (fun exit ->
match exit with
| Exit.Success _ -> audit "transfer committed"
| Exit.Failure _ -> audit "transfer rolled back")kind:member
Runs a finalizer after the flow, however it ends.
Parameters
| Name | Type | Description |
|---|---|---|
| finalizer | Flow<'env, Never, unit> | The cleanup to run; it cannot fail with a typed error. |
| flow | Flow<'env, 'error, 'value> | The source flow. |
Returns
Flow<'env, 'error, 'value>
Verification Examples
render frame |> Flow.ensuring (Flow.delay (fun () -> canvas.Unlock(); Flow.ok ()))kind:member
Runs a handler only if the flow is interrupted.
Parameters
| Name | Type | Description |
|---|---|---|
| handler | Flow<'env, Never, unit> | The cleanup to run on interruption; it cannot fail with a typed error. |
| flow | Flow<'env, 'error, 'value> | The source flow. |
Returns
Flow<'env, 'error, 'value>
Verification Examples
upload |> Flow.onInterrupt (deletePartialFile path)kind:member
A flow that never completes on its own; it ends only when it is interrupted.
Returns
Flow<'env, 'error, 'value>
Verification Examples
// Runs the worker until the service is interrupted, then lets it drain its queue.
let serve (jobs: Queue<string>) (worker: Flow<unit, Never, unit>) : Flow<unit, Never, unit> =
flow {
let! _ = worker |> Flow.forkGraceful (Dequeue.shutdown jobs) (TimeSpan.FromSeconds 5.0)
return! Flow.never
}kind:member
Catches exceptions raised during execution and simple defect outcomes, then maps them to a typed error.
Parameters
| Name | Type | Description |
|---|---|---|
| handler | exn -> 'error | A function of type exn -> 'error to map the exception. |
| flow | Flow<'env, 'error, 'value> | The source flow of type Axial`3 to monitor. |
Returns
Flow<'env, 'error, 'value>
Verification Examples
let flow = Flow.die (System.Exception("boom")) |> Flow.catch (fun ex -> "caught: " + ex.Message)kind:member
Computes a fallback flow from the typed error when the source flow fails.
Parameters
| Name | Type | Description |
|---|---|---|
| fallback | 'error -> Flow<'env, 'error, 'value> | A function that produces a new flow from the error value. |
| flow | Flow<'env, 'error, 'value> | The source flow. |
Returns
Flow<'env, 'error, 'value>
Verification Examples
let flow = Flow.fail "error" |> Flow.orElseWith (fun err -> Flow.succeed "recovered")kind:member
Falls back to another flow when the source flow fails.
Parameters
| Name | Type | Description |
|---|---|---|
| fallback | Flow<'env, 'error, 'value> | The flow to run if the source flow fails. |
| flow | Flow<'env, 'error, 'value> | The source flow. |
Returns
Flow<'env, 'error, 'value>
Verification Examples
let flow = Flow.fail "error" |> Flow.orElse (Flow.succeed "recovered")kind:member
Runs two flows sequentially and combines their successful values into a tuple.
Parameters
| Name | Type | Description |
|---|---|---|
| left | Flow<'env, 'error, 'left> | The first flow to run. |
| right | Flow<'env, 'error, 'right> | The second flow to run. |
Returns
Flow<'env, 'error, ('left * 'right)>
Verification Examples
Flow.zip (Flow.succeed 1) (Flow.succeed 2) |> Flow.run ()kind:member
Combines two flows with a mapping function.
Parameters
| Name | Type | Description |
|---|---|---|
| mapper | 'left -> 'right -> 'value | A function that combines the successful values of both flows. |
| left | Flow<'env, 'error, 'left> | The first flow to run. |
| right | Flow<'env, 'error, 'right> | The second flow to run. |
Returns
Flow<'env, 'error, 'value>
Verification Examples
let flow = Flow.map2 (fun x y -> x + y) (Flow.succeed 1) (Flow.succeed 2)kind:member
Applies a flow-wrapped function to a flow-wrapped value.
Parameters
| Name | Type | Description |
|---|---|---|
| flow | Flow<'env, 'error, ('value -> 'next)> | A flow that contains a function to apply. |
| value | Flow<'env, 'error, 'value> | A flow that contains the value to apply the function to. |
Returns
Flow<'env, 'error, 'next>
Verification Examples
let flow = Flow.apply (Flow.succeed (fun x -> x + 1)) (Flow.succeed 1)kind:member
Combines three flows with a mapping function.
Parameters
| Name | Type | Description |
|---|---|---|
| mapper | 'left -> 'middle -> 'right -> 'value | A function that combines the successful values of all three flows. |
| left | Flow<'env, 'error, 'left> | The first flow to run. |
| middle | Flow<'env, 'error, 'middle> | The second flow to run. |
| right | Flow<'env, 'error, 'right> | The third flow to run. |
Returns
Flow<'env, 'error, 'value>
Verification Examples
let flow = Flow.map3 (fun x y z -> x + y + z) (Flow.succeed 1) (Flow.succeed 2) (Flow.succeed 3)kind:member
kind:member
kind:member
Runs a flow against an environment derived from the outer environment.
Parameters
| Name | Type | Description |
|---|---|---|
| mapping | 'outerEnvironment -> 'innerEnvironment | A function that maps the outer environment to the inner environment. |
| flow | Flow<'innerEnvironment, 'error, 'value> | The flow to run with the inner environment. |
Returns
Flow<'outerEnvironment, 'error, 'value>
Verification Examples
let flow = Flow.succeed 1 |> Flow.localEnv (fun outer -> outer)kind:member
kind:member
Transforms a sequence of values into a flow and stops at the first failure.
Parameters
| Name | Type | Description |
|---|---|---|
| mapping | 'value -> Flow<'env, 'error, 'next> | A function that maps each value to a flow. |
| values | 'value seq | The sequence of values to transform. |
Returns
Flow<'env, 'error, 'next list>
Verification Examples
let flows = [1; 2; 3] |> Flow.traverse (fun x -> Flow.succeed (x * 2))kind:member
Maps values to flows and runs them with bounded concurrency, returning results in input order.
Parameters
| Name | Type | Description |
|---|---|---|
| parallelism | Parallelism | The maximum number of mappings running at once. |
| mapping | 'value -> Flow<'env, 'error, 'next> | Maps each value to a flow. |
| values | 'value seq | The values to map. |
Returns
Flow<'env, 'error, 'next list>
Verification Examples
let! pages = urls |> Flow.traversePar (Parallelism.bounded 8) fetchPagekind:member
Like
traversePar, giving each worker its own resource, acquired once and reused for every value it maps.Parameters
| Name | Type | Description |
|---|---|---|
| parallelism | Parallelism | The maximum number of workers, and so of resources. |
| resource | Resource<'env, 'error, 'resource> | The resource each worker acquires. |
| mapping | 'resource -> 'value -> Flow<'env, 'error, 'next> | Maps a value to a flow, given the worker's resource. |
| values | 'value seq | The values to map. |
Returns
Flow<'env, 'error, 'next list>
Verification Examples
let! matches = commits |> Flow.traverseParUsing (Parallelism.ofProcessors id) openReader (fun reader commit -> search reader commit)kind:member
Runs a flow for each value with bounded concurrency, discarding the results.
Parameters
| Name | Type | Description |
|---|---|---|
| parallelism | Parallelism | The maximum number of flows running at once. |
| action | 'value -> Flow<'env, 'error, unit> | The flow to run for each value. |
| values | 'value seq | The values to process. |
Returns
Flow<'env, 'error, unit>
Verification Examples
do! files |> Flow.forEachPar (Parallelism.ofProcessors id) indexFilekind:member
Like
forEachPar, giving each worker its own resource, acquired once and reused for every value it processes.Parameters
| Name | Type | Description |
|---|---|---|
| parallelism | Parallelism | The maximum number of workers, and so of resources. |
| resource | Resource<'env, 'error, 'resource> | The resource each worker acquires. |
| action | 'resource -> 'value -> Flow<'env, 'error, unit> | The flow to run for each value, given the worker's resource. |
| values | 'value seq | The values to process. |
Returns
Flow<'env, 'error, unit>
kind:member
Transforms a sequence of flows into a flow of a sequence and stops at the first failure.
Parameters
| Name | Type | Description |
|---|---|---|
| flows | Flow<'env, 'error, 'value> seq | The sequence of flows to run. |
Returns
Flow<'env, 'error, 'value list>
Verification Examples
Flow.sequence [Flow.succeed 1; Flow.succeed 2] |> Flow.run ()kind:member
Builds a cold async that runs the workflow when it is started.
Parameters
| Name | Type | Description |
|---|---|---|
| environment | 'env | The environment used by the workflow. |
| flow | Flow<'env, 'error, 'value> | The workflow to describe. |
Returns
Async<Exit<'value, 'error>>
Verification Examples
let handle = workflow |> Flow.toAsync environmentkind:member
Starts the workflow immediately and returns a task handle for its final exit.
Parameters
| Name | Type | Description |
|---|---|---|
| environment | 'env | The environment used by the workflow. |
| flow | Flow<'env, 'error, 'value> | The workflow to start. |
Returns
Task<Exit<'value, 'error>>
Verification Examples
let running = workflow |> Flow.startTask environmentkind:member
Runs the workflow and blocks until the final exit is available.
Parameters
| Name | Type | Description |
|---|---|---|
| environment | 'env | The environment used by the workflow. |
| flow | Flow<'env, 'error, 'value> | The workflow to run. |
Returns
Exit<'value, 'error>
Verification Examples
let exit = workflow |> Flow.run environment
